<?php
// +----------------------------------------------------------------------
// | quanli team
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2020 http://www.fistforward.com/ All rights reserved.
// +----------------------------------------------------------------------
// | Author: create by allen.qiang
// +----------------------------------------------------------------------


/**
 * 配送车辆设置
 * @package  htdocs
 * @subpackage  quanliadmin
 * @author   create by allen.qiang
 */
require 'module/base/systemHandler.class.php';

class pa_vehicle {

    public function execute() {
        global $G_PGLOB ;
        if (isset($_REQUEST['operFlg'])) {

            switch($_REQUEST['operFlg']) {

                case 1: //配送车辆信息列表
                    $this->vehicleList();
                    break;

                case 2: //添加配送车辆
                    $this->vehicleAdd();
                    break;

                case 3: //编辑配送车辆
                    $this->vehicleEdit();
                    break;

                case 4: //查看配送车辆下所有的网点
                    $this->branchesOfVehicle();
                    break;

                default:
                    $G_PGLOB->smarty->assign('msg', '参数错误，请审核后再操作');
                    $G_PGLOB->smarty->display('comm/error.tpl');

            }
        }
    }

    /**
     * 配送车辆信息列表
     *
     */
    private function vehicleList() {

        global $G_PGLOB;

        $G_PGLOB->smarty->display('system/vehicleList.tpl');

    }

    /**
     * 添加配送车辆
     */
    private function vehicleAdd () {

        global $G_PGLOB;

		
        $G_PGLOB->smarty->display('system/vehicleAdd.tpl');

    }

    /**
     * 编辑配送车辆
     */
    public function vehicleEdit() {

        global $G_PGLOB;
        
        $vid = isset($_REQUEST['vid']) ? trim($_REQUEST['vid']) : null;
        if(!is_numeric($vid)){
        	$G_PGLOB->smarty->assign('msg', '参数错误');
            $G_PGLOB->smarty->display('comm/error.tpl');
            die() ;
        }

		$sys_vehicle = new entity('sys_vehicle');
		$sys_vehicle->vehicle_id = $vid;
		if(!$G_PGLOB->DBCA->fetch($sys_vehicle)){
			$G_PGLOB->smarty->assign('msg', '参数错误');
            $G_PGLOB->smarty->display('comm/error.tpl');
            die() ;
		}
        
        $G_PGLOB->smarty->assign('vehicleInfo', $sys_vehicle);
        $G_PGLOB->smarty->display('system/vehicleAdd.tpl');
    }

    //查询配送车辆下所有的网点信息
    function branchesOfVehicle(){

        global $G_PGLOB;

        //接收参数
        $vehicle_id = isset($_REQUEST['id'])?$_REQUEST['id']:'';

        if( empty($vehicle_id) ){
            $G_PGLOB->smarty->assign('msg', '参数错误，请审核后再操作');
            $G_PGLOB->smarty->display('comm/error.tpl');
            die();
        }

        //查询配送车辆信息
        $vehicle_obj = new entity('sys_vehicle');
        $vehicle_obj->vehicle_id = $vehicle_id;

        if( !$G_PGLOB->DBCA->fetch($vehicle_obj) ){
            $G_PGLOB->smarty->assign('msg', '没有找到配送车辆信息');
            $G_PGLOB->smarty->display('comm/error.tpl');
            die();
        }

        $G_PGLOB->smarty->assign('vehicle_obj', $vehicle_obj);
        $G_PGLOB->smarty->assign('vehicle_id', $vehicle_id);
        $G_PGLOB->smarty->display('system/vehicleDetail.tpl');

    }

}